package cn.com.git.workflow.service.dto;

import cn.com.git.common.base.BaseDTO;
import cn.com.git.workflow.common.WorkFlowNodeEnum;
import cn.com.git.workflow.common.WorkFlowNodeOperateEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
  * WorkFlowNode dto
  * @author zhangzhenfu
  * @Description
  * @date 2020/4/12
*/
@ApiModel
@Data
public class WorkFlowNodeDTO extends BaseDTO {

    @ApiModelProperty(value = "节点编号")
    @NotNull
    private String code;
    @ApiModelProperty(value = "节点类型")
    @NotNull
    private String type;
    @ApiModelProperty(value = "节点名称")
    @NotNull
    private String name;

    @ApiModelProperty(value = "节点操作")
    @NotNull
    private List<WorkFlowNodeOperateDTO> operates ;

    public WorkFlowNodeDTO() {
    }

    public WorkFlowNodeDTO(String code, String type, String name) {
        this.code = code;
        this.type = type;
        this.name = name;
    }

    @Data
    public static class WorkFlowNodeOperateDTO {

        @ApiModelProperty(value = "操作类型")
        @NotNull
        private String operateType;

    }

    @ApiModel(description = "流程操作人")
    @Data
    public static class WorkFlowNodeGroupOperatorDTO {

        @ApiModelProperty(value = "操作人id")
        @NotNull
        private Integer operatorId;

        @ApiModelProperty(value = "操作人名称")
        @NotNull
        private String operatorName;

    }

    public static WorkFlowNodeDTO.WorkFlowNodeOperateDTO newNodeOperate(String operateType){
        WorkFlowNodeDTO.WorkFlowNodeOperateDTO btn = new  WorkFlowNodeDTO.WorkFlowNodeOperateDTO();
        btn.setOperateType(operateType);
        return btn;
    }

    public static WorkFlowNodeGroupOperatorDTO newNodeOperateGroupUser(Integer operatorId, String operatorName){
        WorkFlowNodeGroupOperatorDTO operator = new WorkFlowNodeGroupOperatorDTO();
        operator.setOperatorId(operatorId);
        operator.setOperatorName(operatorName);
        return operator;
    }

    /**
     * 实例化节点
     * @return
     */
    public static WorkFlowNodeDTO buildNode(WorkFlowNodeEnum nodeEnum){
        WorkFlowNodeDTO node = new  WorkFlowNodeDTO(nodeEnum.getCode(),nodeEnum.getType(),nodeEnum.getName());
        return node;
    }

}